package com.cd.serlet;

import cn.hutool.core.lang.copier.SrcToDestCopier;
import cn.hutool.json.JSONUtil;
import com.cd.dao.ClassesDao;
import com.cd.entity.Classes;
import com.cd.entity.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
    private ClassesDao dao = null;
    @Override
    public void init() throws ServletException {
        dao = new ClassesDao();
    }
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        List<Classes> classes = dao.findAll();
        String str = JSONUtil.toJsonStr(classes);
        resp.getWriter().write(str);
        resp.getWriter().flush();
    }

}
